package com.t14;

/**
 * Created by xuyiwei on 2018/8/11.
 */
public class IsInstanceTest {
    public static void main(String[] args) {
        Father f = new Son();
        //根据对象去判断 不是根据引用
        System.out.println(Son.class.isInstance(f));//这个例子根据实际对象去比较而不是引用 true
        System.out.println(Father.class.isInstance(f));//true  子类可以向上转成父类
        Son s = new Son();
        System.out.println(Son.class.isInstance(s));//true
        System.out.println(Father.class.isInstance(s));//true  子类可以向上转成父类
        Father fz = new Father();
        System.out.println(Son.class.isInstance(fz));//false  父类不能代表子类
        Son sz = new Son();
        System.out.println(Son.class.isInstance(sz));//true
    }
}
